﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
using Abp.Application.Services.Dto;
using Abp.Auditing;
using Abp.Authorization.Users;
using Abp.AutoMapper;
using KelonProud.Administration.Domain.Authorization;
using System.Linq;

namespace KelonProud.Administration.Dtos
{
    [AutoMap(typeof(User))]
   public class UserInputDto: EntityDto<long>
    {
        public int? TenantId { get; set; }

        [Required(ErrorMessage = "用户账号必须填写"), StringLength(20, MinimumLength = 4, ErrorMessage = "用户账号长度必须在4-20个字符之间")]
        public string UserName { get; set; }

        [Required(ErrorMessage = "用户名称必须填写")]
        [StringLength(20, MinimumLength = 2, ErrorMessage = "用户姓名长度必须在2-20个字符之间")]
        public string Name { get; set; }

        public string Surname { get; set; }

        [Required(ErrorMessage = "邮箱必须填写")]
        [RegularExpression(@"^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+$", ErrorMessage = "邮箱格式不正确")]
        public string EmailAddress { get; set; }

        [Phone]
        public string PhoneNumber { get; set; }

        public bool IsActive { get; set; }

        public string[] RoleNames { get; set; }

        [DisableAuditing]
        public string Password { get; set; }

        public bool IsLockoutEnabled { get; set; }

        public  long? OrganizationUnitId { get; set; }

        public void Normalize()
        {
            if (RoleNames == null)
            {
                RoleNames = new string[0];
            }
        }

        public virtual string[] RoleIds { get; set; }

        public IEnumerable<RoleOutPutDto> RoleDtos { get; set; }

        public bool NavIsInRole(RoleOutPutDto roleOutPut)
        {
            return RoleIds?.Contains(roleOutPut.Id.ToString()) ?? false;
        }
    }

    [AutoMap(typeof(User))]
    public class UserOutputDto : UserInputDto
    {
        public string FullName { get; set; }

        public DateTime? LastLoginTime { get; set; }

        public DateTime CreationTime { get; set; }

        public int AccessFailedCount { get; set; }

        public bool IsDeleted { get; set; }

        public bool IsEmailConfirmed { get; set; }

        public bool IsPhoneNumberConfirmed { get; set; }
    }

    public class UserModifyPwdInPut
    {
        [Required]
        public string OldPassWord { get; set; }

        [Required,RegularExpression("(?!^\\d+$)(?!^[a-zA-Z]+$)(?!^[_#@]+$).{6,}",ErrorMessage = "密码不符合规则")]
        public string NewPassWord { get; set; }

        [Required]
        public string NewPassWordR { get; set; }
    }
}
